$(document).ready(function() {
	//ajaxform
	var options = { 
		beforeSubmit:showRequest,//表单验证方式
        success:showResponse  // post-submit callback 
    }; 

    $('#ajaxForm').ajaxForm(options); 

    function showResponse(responseText, statusText)  {
		if (statusText == 'success') {
			var responseText=eval('('+responseText+')');
			if(responseText.state == 'SUCCESS'){
				formDialog.content(responseText.message);
				formDialog.title('操作成功');
				formDialog.icon('succeed');
				var timer,i=2;
				var fn = function () {
					formDialog.title(i + '秒后关闭');
					if (!i){
						formDialog.close();
						clearInterval(timer);
						if(responseText.url==''){
							window.location.reload();
						}else{
							window.location.href = responseText.url;	
						}
					}
					i --;
				};
				timer = setInterval(fn, 1000);

			}else{
				formDialog.content(responseText.state);
				formDialog.title('错误提示');
				formDialog.icon('error');
			}			
		}else{
			formDialog.content('服务器错误');
			formDialog.title('错误提示');			
		}
	} 

	function showRequest(){
		 validata = $("form.form-validata").valid();
		 if (validata){
		 	formDialog = art.dialog({
				title : '消息提示',
			  content : '<img src="/tpl/Admin/common/image/loadding.gif">',
			     lock : true
			})
		 }
		 return validata;
	}

	//validation验证
	$("form.form-validata").validate({
		errorElement: "span",
        errorClass: "help-inline error",
	})

});


function uploadImage(url , domid){
	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	lock:true,
	title:'上传图片',
	width:500,
	height:300,
	});
}

function delImage(domid){
	$("#"+domid).val("");
	$("#"+domid+"_src").attr('src','/tpl/static/image/image.jpg');
}

function selectArticle(url , domid){
	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	lock:true,
	title:'选择推广素材',
	width:500,
	height:300,
	});
}

function CheckAll(form){
  for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
  	if (e.name != 'chkall'){
	e.checked = form.checkall.checked;
	}
   }
}

function openWindow(title , url , domid , width, height){
	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	title:title,
	lock:true,
	width:width,
	height:height,
	});
}